package com.lt.lumentracks.controller;


import com.lt.lumentracks.entity.vo.common.PageVO;
import com.lt.lumentracks.entity.vo.common.Result;
import com.lt.lumentracks.entity.vo.user.UserVO_follow;
import com.lt.lumentracks.service.IFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 关注表 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-09-03
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Autowired
    private IFollowService iFollowService;

    /** 关注或取关
     * @param userId 关注者
     * @param followUserId 被关注者
     * @param isFollow 操作 true-关注，false-取关
     */
    @PutMapping("/{id}/{isFollow}")
    public Result<Void> follow(@RequestParam Integer userId,
                         @PathVariable("id") Integer followUserId,
                         @PathVariable("isFollow") Boolean isFollow) {
        return iFollowService.follow(userId, followUserId, isFollow);
    }


    // 查询是否关注了某用户
    @GetMapping("/isFollow/{id}")
    public Result<Boolean> isFollow(@RequestParam Integer userId,
                           @PathVariable("id") Integer followUserId) {
        return iFollowService.isFollow(userId, followUserId);
    }

    // 查询我的关注
    @GetMapping("/getFollows/{userId}")
    public Result<PageVO<UserVO_follow>> getFollows(@PathVariable("userId") Integer userId,
                                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        PageVO<UserVO_follow> vo = iFollowService.getFollows(userId, pageNum, pageSize);
        return Result.success(vo);
    }

    // 根据用户名字模糊查询我的关注
    @GetMapping("/getFollowsByName")
    public Result<PageVO<UserVO_follow>> getFollowsByName(@RequestParam("userId") Integer userId,
                                                          @RequestParam("followName") String followName,
                                                          @RequestParam(defaultValue = "1") Integer pageNum,
                                                          @RequestParam(defaultValue = "10") Integer pageSize) {
        PageVO<UserVO_follow> vo = iFollowService.getFollowsByName(userId, followName, pageNum, pageSize);
        return Result.success(vo);
    }

    // 查询我的粉丝
    @GetMapping("/getFans/{userId}")
    public Result<PageVO<UserVO_follow>> getFans(@PathVariable("userId") Integer userId,
                                             @RequestParam(defaultValue = "1") Integer pageNum,
                                             @RequestParam(defaultValue = "20") Integer pageSize) {
        PageVO<UserVO_follow> vo = iFollowService.getFans(userId, pageNum, pageSize);
        return Result.success(vo);
    }

}
